import asyncio
from fastapi import UploadFile, File
from mian.model.globalModel import GlobalResponse
from mian.methods import Public


class UploadRoute:
    """
    文件上传路由类
    """

    def uploadRoute(self, app):
        """
        文件上传路由
        :param app: fastapi对象
        """
        app.add_api_route(path="/upload/wordModel", endpoint=self.saveWordModel, methods=['POST'], tags=['上传'],
                          summary='word模板', description="用于文件转换", response_model=GlobalResponse)

    public = Public()

    async def saveWordModel(self, file: UploadFile = File(...)):
        """
        word模板上传
        :param file: 模板文件
        """
        response = await self.public.saveFile(file)
        return response
